<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item>
        <el-date-picker
          v-model="dateRange"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="车号" prop="chehao">
        <el-input
          v-model="queryParams.chehao"
          placeholder="请输入车号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="仓库编号 " prop="ckbh">
        <el-input
          v-model="queryParams.ckbh"
          placeholder="请输入仓库编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="卸车部门" prop="xcbm">
        <el-input
          v-model="queryParams.xcbm"
          placeholder="请输入卸车部门 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料名称" prop="wlmc">
        <el-input
          v-model="queryParams.xcbm"
          placeholder="请输入物料名称 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="称重编号" prop="czbh">
        <el-input
          v-model="queryParams.xcbm"
          placeholder="请输入称重编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单编号" prop="ddbh">
        <el-input
          v-model="queryParams.xcbm"
          placeholder="请输入订单编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-select v-model="selectedValue" placeholder="请选择类型" clearable>
          <el-option label="个人合同粮" :value="1"></el-option>
          <el-option label="散户玉米" :value="2"></el-option>
          <el-option label="出库" :value="3"></el-option>
          <el-option label="采购订单玉米" :value="4"></el-option>
          <el-option label="入库" :value="5"></el-option>
          <el-option label="所有玉米" :value="6"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-checkbox :true-label="'是'" :false-label="'否'" v-model="dropCar">
          是否退车
        </el-checkbox>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:guozhong:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!-- v-loading="loading" -->
    <el-table
      v-loading="loading"
      :data="guozhongList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="称重编号" align="center" prop="czbh" />
      <el-table-column label="订单编号" align="center" prop="ddbh" />
      <el-table-column label="车号" align="center" prop="chehao" />
      <el-table-column label="供应商名" align="center" prop="gysdm" />
      <el-table-column label="公司名" align="center" prop="gsmc" />
      <el-table-column label="物流名称" align="center" prop="wlmcc" />
      <el-table-column label="物料名" align="center" prop="wlmc" />
      <el-table-column label="仓库编号" align="center" prop="ckbh" />
      <el-table-column label="仓库名" align="center" prop="ckmc" />
      <el-table-column label="进厂重量" align="center" prop="mz" />
      <el-table-column label="进厂时间" align="center" prop="mzsj" />
      <el-table-column label="出厂重量" align="center" prop="pz" />
      <el-table-column label="出厂时间" align="center" prop="pzsj" />
      <el-table-column label="化验扣重" align="center" prop="hykz" />
      <el-table-column label="净重" align="center" prop="jz" />
      <el-table-column label="结算重量" align="center" prop="jszl" />
      <el-table-column label="结算单价" align="center" prop="jsdj" />
      <el-table-column label="结算金额" align="center" prop="jsje" />
      <el-table-column label="卸车部门" align="center" prop="xcbm" />
      <el-table-column label="水分" align="center" prop="sf" />
      <el-table-column label="扣重" align="center" prop="kz" />
      <el-table-column label="进厂地磅" align="center" prop="dbh" />
      <el-table-column label="出厂地磅" align="center" prop="dbh2" />
      <el-table-column label="进厂司磅员" align="center" prop="czymc" />
      <el-table-column label="出厂司磅员" align="center" prop="czymc2" />
      <el-table-column label="订单物料数量" align="center" prop="ddwlsl" />
      <el-table-column label="内外销" align="center" prop="sd_dwx" />
      <el-table-column label="包装物名" align="center" prop="sd_bzwmc" />
      <el-table-column label="最低重" align="center" prop="fw_zdz" />
      <el-table-column label="最高重" align="center" prop="fw_zgz" />
      <el-table-column label="合同号" align="center" prop="jshth" />
      <el-table-column label="订单原始重量" align="center" prop="ddyszl" />
      <el-table-column label="订单原始毛重" align="center" prop="ddysmz" />
      <el-table-column label="订单原始净重" align="center" prop="ddysjz" />
      <el-table-column label="发卡时间" align="center" prop="fksj" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
  
  <script>
import { listGuozhong,listTotalGuozhong } from "@/api/system/Fdongbei/guozhong";

export default {
  name: "Guozhong",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedTbHuayan: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // tb表格数据
      guozhongList: [],
      // 化验--》表格数据
      tbHuayanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginTime: null,
        endTime: null,
        chehao: null,
        wlmc: null,
        ckbh: null,
        xcbm: null,
        czbh: null,
        ddbh: null,
        yj: null,
        bj: null,
      },
      dateRange: this.timeDefault(),
      dropCar: null,
      selectedValue: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        beginTime: [{ required: true, message: " 不能为空", trigger: "blur" }],
        endTime: [{ required: true, message: " 不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //设置默认时间

    // 默认时间
    timeDefault() {
      let date = new Date();

      // 通过时间戳计算
      let defalutStartTime = date.getTime() - 7 * 24 * 3600 * 1000; // 转化为时间戳
      let defalutEndTime = date.getTime();

      let startDateNs = new Date(defalutStartTime);
      let endDateNs = new Date(defalutEndTime);

      // 月，日，时，分，秒 不够10补0
      defalutStartTime =
        startDateNs.getFullYear() +
        "-" +
        (startDateNs.getMonth() + 1 >= 10
          ? startDateNs.getMonth() + 1
          : "0" + (startDateNs.getMonth() + 1)) +
        "-" +
        (startDateNs.getDate() >= 10
          ? startDateNs.getDate()
          : "0" + startDateNs.getDate()) +
        " " +
        (startDateNs.getHours() >= 10
          ? startDateNs.getHours()
          : "0" + startDateNs.getHours()) +
        ":" +
        (startDateNs.getMinutes() >= 10
          ? startDateNs.getMinutes()
          : "0" + startDateNs.getMinutes()) +
        ":" +
        (startDateNs.getSeconds() >= 10
          ? startDateNs.getSeconds()
          : "0" + startDateNs.getSeconds());

      defalutEndTime =
        endDateNs.getFullYear() +
        "-" +
        (endDateNs.getMonth() + 1 >= 10
          ? endDateNs.getMonth() + 1
          : "0" + (endDateNs.getMonth() + 1)) +
        "-" +
        (endDateNs.getDate() >= 10
          ? endDateNs.getDate()
          : "0" + endDateNs.getDate()) +
        " " +
        (endDateNs.getHours() >= 10
          ? endDateNs.getHours()
          : "0" + endDateNs.getHours()) +
        ":" +
        (endDateNs.getMinutes() >= 10
          ? endDateNs.getMinutes()
          : "0" + endDateNs.getMinutes()) +
        ":" +
        (endDateNs.getSeconds() >= 10
          ? endDateNs.getSeconds()
          : "0" + endDateNs.getSeconds());

      return [defalutStartTime, defalutEndTime];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询tb列表 */
    getList() {
      this.loading = true;
      if (this.dateRange.length === 0) {
        this.$alert("请输入要查询的月份！", "提示", {
          confirmButtonText: "确定",
          type: "waring",
        });
      } else {
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      }
      if (this.dropCar == true) {
        this.queryParams.yj = "是";
      } else {
        this.queryParams.yj = null;
      }
      this.queryParams.bj = this.selectedValue;
      listTotalGuozhong(this.queryParams).then((response) => {
        this.guozhongList = response.data.carTotalInfoVoList;

        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        czbh: "",
        chehao: "",
        gysdm: "",
        ckbh: "",
        xcbm: "",
        yj: null,
      };
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.czbh);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/guozhong/export",
        {
          ...this.queryParams,
        },
        `guozhong_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>